import 'package:flutter/material.dart';

/*
 * @class CustomSwitch
 * @author: ZhongWb
 * @date: 2020/1/3 15:07
 * @description 自定义开关
 **/
class CustomSwitch extends StatelessWidget {
  bool value;
  double height;
  double width;
  Color actColor;
  Color bgColor;
  GestureTapCallback onTap;
  CustomSwitch({this.onTap,this.value:true,this.width:30,this.height:20,this.actColor:Colors.white,this.bgColor:Colors.green});
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap ?? (){},
      child: Container(
        width: width,
        height: height,
        padding: EdgeInsets.all(0),
        alignment: Alignment.center,
        child: Row(
          mainAxisAlignment:value? MainAxisAlignment.end : MainAxisAlignment.start,
          children: <Widget>[
            Container(
              margin: EdgeInsets.all(value?1:0),
              width: value?(height-2):height,
              height: value?(height-2):height,
              decoration: BoxDecoration(
                  color: actColor,
                  border: Border.all(color: Colors.grey[200]),
                  borderRadius: BorderRadius.circular(height)
              ),
            ),
          ],
        ),
        decoration: BoxDecoration(
          color: bgColor,
          border: Border.all(color: Colors.grey[200]),
          borderRadius: BorderRadius.circular(15),
        ),
      ),
    );
  }
}
